#pragma once
//#include <vector>
#include "..\lib\container\List.h"
#include "..\dxstdafx.h"
#include <vector>

namespace ds {

const uint32 MAX_LAYERS = 32;
const uint32 MAX_NAME_LENGTH = 15; 
const uint32 MAX_NODES = 4096;

enum WorldMask {
	WL_NONE,
	WL_FORWARD,
	WL_RENDERTARGET
};

typedef uint32 WorldLayer;

class Node;
class ResManager;

class World {

struct LayerNode {
	WorldLayer layer;
	Node* node;
};

public:
	World();
	~World();
	// layer management
	WorldLayer createLayer(WorldMask wm = WL_FORWARD);
	WorldLayer createLayer(const char* name,WorldMask wm = WL_FORWARD);
	WorldLayer getLayerByName(const char* name);
    void activateLayer(const WorldLayer& layer);
    void deactivateLayer(const WorldLayer& layer);
	void activateLayerByName(const char* name);
	void deactivateLayerByName(const char* name);
    void getActiveLayers(List<WorldLayer>& list);
	void setMask(WorldLayer layer,WorldMask wm);
	// handling nodes
	Node* getNode(const std::string& name);
	void attachNode(Node* node,const WorldLayer& layer);
	void attachNode(Node* node,const char* layerName);
	void getActiveNodes(List<Node*>& list,WorldMask wm = WL_FORWARD);
	void getActiveNodes(List<Node*>& list,std::vector<WorldLayer>& layers,WorldMask wm = WL_FORWARD);
	void update(float elapsed);
	void initializeNodes(ResManager& resourceManager);	
	void debug();
private:
	//
	void setName(WorldLayer layer,const char* name);
	void getName(WorldLayer layer,char* ret);
	char* m_NameMapping;
	//LayerNodes m_LayerNodes;
	LayerNode* m_LayerNodes;
	uint32 m_NodeCounter;
	uint32* m_Data;
	uint32 m_Counter;
	List<WorldLayer> m_ActiveLayers;
	bool m_Dirty;
};

}

